package com.wpw.dream.thread;

public class DaemonThread {

	public static void main(String[] args) {
		Thread daemonThread = new Thread(new DaemonRunner());
		daemonThread.setDaemon(true);
		daemonThread.start();

		//userRunner线程执行完了，但是守护线程还没有执行完，就结束了。
		new Thread(new UserRunner()).start();
	}
}

class DaemonRunner implements Runnable {
	@Override
	public void run() {
		for (int i = 1; i <= 100; i++) {
			System.out.println("daemon thread:" + i);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}

class UserRunner implements Runnable {
	@Override
	public void run() {
		for (int i = 1; i <= 3; i++) {
			System.out.println("user thread:" + i);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}